<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
<meta charset="utf-8" />
<title>代理商品 - 库存列表</title>
<?php include($this->c['_homes']['_viewsHome'].'/_global/_head.php');?>
</head>
<!-- BEGIN BODY -->
<body class="page-header-fixed page-sidebar-fixed">
<!-- BEGIN HEADER -->
<?php include($this->c['_homes']['_viewsHome'].'/_global/head.php');?>
<!-- END HEADER -->
<div class="clearfix"></div>
<!-- BEGIN CONTAINER -->
<div class="page-container" > 
  <!-- BEGIN HORIZONTAL MENU PAGE SIDEBAR1 -->
  <?php include($this->c['_homes']['_viewsHome'].'/_global/menu.php');?>
  <!-- END BEGIN HORIZONTAL MENU PAGE SIDEBAR --> 
  <!-- BEGIN PAGE -->
  <div class="page-content"> 
    <!-- BEGIN PAGE HEADER-->
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN PAGE TITLE & BREADCRUMB-->
        <h3 class="page-title"> 库存列表 </h3>
        <ul class="page-breadcrumb breadcrumb">          
          <li> <i class="icon-home"></i> <a href="/manage">后台</a> <i class="icon-angle-right"></i> </li>
          <li> 代理商品 <i class="icon-angle-right"></i> </li>
          <li>库存列表</li>
        </ul>
        <!-- END PAGE TITLE & BREADCRUMB--> 
      </div>
    </div>
    <!-- END PAGE HEADER--> 
    <!-- BEGIN PAGE CONTENT-->     
    <div class="row">
      <div class="col-md-12">
        <div class="portlet box">
          <div class="booking-search">
            <form action="" role="form" method="get">
              <div class="row form-group">
                <div class="col-md-12">
                  <h4>姓名： <strong><?=$this->user['name'];?></strong> 手机号码：<strong><?=$this->user['mobile'];?></strong> </h4>
                </div>                                
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE TABLE PORTLET-->
        <div class="portlet box blue">
          <div class="portlet-title">
            <div class="caption"><i class="icon-list"></i>列表</div>            
          </div>
          <div class="portlet-body">
            <div class="table-scrollable">
             <table class="table table-striped table-bordered table-hover dataTable">
                <thead>
                  <tr>                    
                    <th>商品ID</th>
                    <th>名称</th>                    
                    <th>库存</th>                    
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
            			if($this->data)
            			{
            				foreach($this->data as $goods_id=> $name){		
					
            																
            			?>
                  <tr>
                    <td><?=$goods_id;?></td>
                    <td><?=$name;?></td>                    
                    <td><?=$this->stock[$goods_id] ? : 0;?></td>
                    <td>					
                    <a href="javascript:_recharge(<?=$goods_id;?>,'<?=addslashes($name);?>');" class="btn btn-xs blue"><i class="icon-edit"></i> 充值</a>
            			</td>
                  </tr>
                  <?
        					}
        				}
        				?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        
        <!-- END SAMPLE TABLE PORTLET--> 
      </div>
    </div>
    <!-- END PAGE CONTENT--> 
  </div>
  <!-- END PAGE --> 
</div>
<!-- END CONTAINER -->

<div style="position: fixed;width: 100%; height: 100%; top: 0; left: 0; background: rgba(0,0,0,0.5); display: none; z-index: 9999;" id="popmask"></div>
<div style="position: fixed;width:50%; min-width:200px;height: 50%; z-index: 10000;  min-height:200px; top: 25%; left: 25%; background: #fff; border: 2px solid #ccc; padding: 30px; line-height: 30px; font-weight: bold; display: none;" id="popstock">


<div class="row">
      <div class="col-md-12"> 
        <!-- BEGIN SAMPLE FORM PORTLET-->
        <form class="form-horizontal" method="post" onSubmit="return chkfrm();" role="form">
          
          <div class="tabbable tabbable-custom boxless">
            <div class="tab-content"> 
              <!--Tab0-->
              <div class="tab-pane active" id="tab_0">
                <div class="portlet box">
                  <div class="portlet-body form">
                    <div class="form-body">
                      <div class="form-group">
                        <label  class="col-md-2 control-label">商品ID</label>
                        <div class="col-md-9">
                        <h5 id="gid"></h5>                          
                        </div>
                      </div>
                      
                      <div class="form-group">
                        <label  class="col-md-2 control-label">商品名称</label>
                        <div class="col-md-9">
                          <h5 id="gname"></h5>
                        </div>
                      </div>
                      <hr>
                      <div class="form-group">
                        <label  class="col-md-2 control-label">充值库存数量<span class="required">*</span></label>
                        <div class="col-md-6">
                          <input type="text"  value="" id="stock_number" maxlength="10" class="form-control">
                        </div>
                      </div> 
             
                    </div>
                    <div class="form-actions fluid">
                      <div class="col-md-offset-2 col-md-2">
                        <button type="button" class="btn blue" onClick="_save();">提交</button>
                        <button type="button" class="btn default" onClick="_cancel();">取消</button>
                      </div>
                    </div>
                  </div>
                </div>
              </div>                            
              <!--End Tab--> 
            </div>
          </div>
        </form>
        <!-- END SAMPLE FORM PORTLET--> 
      </div>
    </div>

</div>

<?php include($this->c['_homes']['_viewsHome'].'/_global/_footer.php');?>
<script type="text/javascript">
jQuery(document).ready(function() {    
	App.init();
});

var _goods_id = 0;
function _recharge(id,name)
{
  _goods_id = id;
  $("#gid").html(id);
  $("#gname").html(name);

  $("#popmask,#popstock").css("display","block");
}

function _cancel()
{
  $("#popmask,#popstock").css("display","none");
}

function _save()
{
  if( $("#stock_number").prop("value")=="")
  {
    swal("请填写充值库存数量");
  }
  else
  {

    $.post("/agent/ajax",
      {
        "act":"recharge",
        "goods_id":_goods_id,
        "number":$("#stock_number").prop("value"),
        "uid":<?=$this->user['uid'];?>,
        "mr":Math.random()
      },function(json){
        console.log(json);
        if(json.code==200)
        {
          swal("充值成功！",false,"success");
          setTimeout(function(){

            window.location.reload();

          },2000);
        }
        else
        {
          swal("充值失败","错误代码:"+json.code,"error");
        }
      },"json");

  }
}
</script> 
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>